package com.ChengXiZi.controller.user;

import com.ChengXiZi.dto.PostAddDTO;
import com.ChengXiZi.dto.PostPageDTO;
import com.ChengXiZi.result.PageResult;
import com.ChengXiZi.result.Result;
import com.ChengXiZi.service.PostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户端-帖子接口
 */

@Slf4j
@RestController
@Api(tags = "帖子接口")
@RequestMapping("/post")
public class PostController {

    @Autowired
    private PostService postService;

    /**
     * 发帖
     * @param postAddDTO
     * @return
     */
    @PostMapping
    @ApiOperation("发帖")
    public Result posted(@RequestBody PostAddDTO postAddDTO) {
        log.info("发帖：{}",postAddDTO);
        postService.posted(postAddDTO);
        return Result.success();
    }

    /**
     * 分页查询
     * @param postPageDTO
     * @return
     */
    @PostMapping("/search")
    @ApiOperation("分页查询")
    public Result Page(@RequestBody PostPageDTO postPageDTO) {
        log.info("分页查询：{}",postPageDTO);
        PageResult pageResult = postService.page(postPageDTO);
        return Result.success(pageResult);
    }
}
